package com.shenjialin.Tank;

import com.shenjialin.Game.Bullet;
import com.shenjialin.Game.Explode;
import com.shenjialin.Game.GameFrame;
import com.shenjialin.util.BulletsPool;
import com.shenjialin.util.Constant;
import com.shenjialin.util.MyUtil;

import java.util.*;
import java.awt.*;
import java.util.List;

/**
 * 坦克类
 */
public class MyTank extends Tank{

    protected static Image[] tankImg;

    static {
        tankImg = new Image[4];
        tankImg[0] = MyUtil.createImage("res/tankup.png");
        tankImg[1] = MyUtil.createImage("res/tankdown.png");
        tankImg[2] = MyUtil.createImage("res/tankleft.png");
        tankImg[3] = MyUtil.createImage("res/tankright.png");

    }

    private void drawImgTank(Graphics g) {
        g.drawImage(tankImg[dir], x - RADIUS, y - RADIUS, null);
    }
    public void draw(Graphics g) {

        logic();
//        drawTank(g);
        drawImgTank(g);

        drawBullets(g);

        drawName(g);

        bar.draw(g);
    }
    public MyTank(int x, int y, int dir) {
        super(x, y, dir);
        setHp(2000);
        setAtk(200);
        setColor(Color.WHITE);
    }

    @Override
    protected void die(){
//        GameFrame.setGameState(Constant.STATE_OVER);
//        // 游戏结束 切换游戏状态
        delayToOver(1000);
        return;
    }

    @Override
    public void fire() {
        int bulletX = x;
        int bulletY = y;
        switch (dir) {
            case DIR_UP:
                bulletY -= RADIUS;
                break;
            case DIR_DOWN:
                bulletY += RADIUS;
                break;
            case DIR_LEFT:
                bulletX -= RADIUS;
                break;
            case DIR_RIGHT:
                bulletX += RADIUS;
                break;
        }
        //
        Bullet bullet = BulletsPool.get();
        bullet.setBulletType(Bullet.BULLET_TYPE1);
        bullet.setX(bulletX);
        bullet.setY(bulletY);
        bullet.setDir(dir);
        bullet.setSpeed(speed /2);
        bullet.setAtk(atk);
        bullet.setColor(color);
        bullet.setVisible(true);
        //= new Bullet(bulletX,bulletY,dir,atk,color);
        bullets.add(bullet);
    }




}
